<!DOCTYPE html>
<html>
	<head lang="en">
		<meta charset="utf-8" />
		<title>forget</title>
		<link rel="stylesheet" type="text/css" href="../../css/public.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/proList.css" />
		<link rel="stylesheet" type="text/css" href="../../css/forget.css" />
	</head>
	<body>
		<!----------------------------------------order------------------>
		<div class="order cart">
			<!-----------------logo------------------->
			<div class="logo">
				<h1 class="wrapper clearfix">
					<a href="index"><img class="fl" src="../../img/temp/logo2.png"></a>
				</h1>
			</div>
			<div class="forCon">
				<p>安全设置-找回密码</p>
				<ul>
					<li class="on"><span>01/</span>输入登录名</li>
					<li><span>02/</span>验证信息</li>
					<li><span>03/</span>重置密码</li>
				</ul>
				<div class="formCon">
					<!--步骤1-->
					<form action="" id="form-judgeUserName" method="post" class="one">
						<input type="text" id="username" name="username" value="" placeholder="用户名"><label>请输入用户名</label><br />
						<input type="button" style="background-color: #c10000"  id="judgeUserName" value="下一步" class="nextInit">
					</form>
					<!--步骤2-->
					<form action="#" id="form-judgeContact" method="post" class="two">
<!--						<p>电子邮箱：<span>114081*****qq.com</span></p>-->
<!--						<p class="tip">验证邮件已发往你的电子邮箱，请点击邮件中的链接完成验证</p>-->
						<input type="text" name="email" id="email" value="" placeholder="邮箱"><label>请输入注册邮箱</label><br />
						<input type="text" name="phone" id="phone" value="" placeholder="手机号"><label>请输入注册手机号</label><br />
						<input type="button" style="background-color: #c10000" id="judgeContact" value="下一步" class="next1">
					</form>
					<!--步骤3-->
					<form action="#" id="form-newPassword" method="post" class="three">
						<label>新密码：</label><input style="border:1px solid #dbdbdb; font-size: 20px;padding-left:10px; " type="password" id="newPassword" name="newPassword" value=""><br />
						<p class="op">提示:6-16 个字符，需使用字母、数字组合，不能使用纯数字、纯字母</p>
						<label>确认密码：</label><input style="border:1px solid #dbdbdb; font-size: 20px;padding-left:10px; " type="password" id="newPasswordAgain" onblur="check()"    value=""><br />
						<input type="button" style="background-color: #c10000" id="btn-newPassword" value="完成">
					</form>
				</div>
			</div>
		</div>
		
		<script src="../../js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/public.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/pro.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/sweetalert.min.js"></script>
	</body>
<script>

	$(function () {
		//第一个form表单确认用户名
		$('#judgeUserName').click(function () {
			$.ajax({
				url: "/queryUserName",
				type: "POST", //提交方式
				data: $("#form-judgeUserName").serialize(),
				dataType: "json",
				success: (function (json) {
					if (json.state == 200) {
						swal({
							title: '用户名输入正确',
							icon: 'success'
						}).then(function () {
							// location.href = 'index'
						})
						$(".two").show();
						$(".one").hide();
						$(".forCon ul li").eq(1).addClass("on").siblings("li").removeClass("on");
					} else {
						swal({
							title: '用户名输入有误',
							icon: 'warning',
							text: json.message,
							button: {
								text: "确认",
								value: true,
							}
						}).then(function (isok) {
							if (isok) {
								return false;
							}
						})
					}
				})
			})
		})


		//第二个form表单确认用户注册的手机和邮箱
		$('#judgeContact').click(function () {
		$.ajax({
			url: "/queryContact",
			type: "POST", //提交方式
			data: $("#form-judgeContact").serialize(),
			dataType: "json",
			success: (function (json) {
				if (json.state == 200) {
					swal({
						title: '验证成功',
						icon: 'success'
					}).then(function () {
						// location.href = 'index'
					})
					$(".two").hide();
					$(".one").hide();
					$(".forCon ul li").eq(1).addClass("on").siblings("li").removeClass("on");
					$(".three").show();
				} else {
					swal({
						title: '用户信息输入错误',
						icon: 'warning',
						text: json.message,
						button: {
							text: "确认",
							value: true,
						}
					}).then(function (isok) {
						if (isok) {
							return false;
						}
					})
				}
			})
		})
	})


		// function check() {
		// 	var pwd1 = document.getElementById("newPassword").value;
		// 	var pwd2 = document.getElementById("newPasswordAgain").value;
		// 	if (pwd1 != pwd2)
		// 			// alert("您输入的两次密码不一致");
		// 		swal({
		// 			title: '您输入的两次密码不一致',
		// 			icon: 'error'
		// 		}).then(function () {
		// 			return false
		// 		})
		// }

		$(function () {
			//失去焦点时自动匹配正确规范的课程编号
			$('#newPassword').blur(function () {
				var newPassword = $('#newPassword').val();
				var newPasswordPatt = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
				if (!newPasswordPatt.test(newPassword)) {
					// alert("格式错误，请按照要求输入复合要求的密码！")
					swal({
						title: '密码格式错误',
						icon: 'warning',
						text: "请确认输入密码符合规范。",
						button: {
							text: "确认",
							value: true,
						}
					}).then(function (isok) {
						if (isok) {
							return false;
						}
					})
				} else {
					// alert("密码符合要求")
					swal({
						title: '密码符合要求',
						icon: 'success',
					}).then(function () {
					})
				}
			})
		})



		function checkpassword() {
			var password = document.getElementById("newPassword").value;
			var repassword = document.getElementById("newPasswordAgain").value;

			if(password == repassword) {
				// document.getElementById("tishi").innerHTML="<br><font color='green'>两次密码输入一致</font>";
				document.getElementById("btn-newPassword").disabled = false;

			}else {
				swal({
					title: '两次输入密码不一致!',
					icon: 'warning',
					button: {
						text: "确认",
						value: true,
					}
				}).then(function (isok) {
					if (isok) {
						location.href = 'remima'
					}
				})
				// document.getElementById("tishi").innerHTML="<br><font color='red'>两次输入密码不一致!</font>";
				document.getElementById("btn-newPassword").disabled = true;
			}
		}


		//第三个form表单重新设置用户新密码
		$('#btn-newPassword').click(function () {
			var newPassword = $('#newPassword').val();
			var newPasswordPatt = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
			var password = document.getElementById("newPassword").value;
			var repassword = document.getElementById("newPasswordAgain").value;

			if($.trim(newPassword)==null || $.trim(newPassword)==''){
				swal({
					title : "修改操作提示",
					type : "error",
					text : "请检查新密码是否填写完整",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			if (!newPasswordPatt.test(newPassword)){
				swal({
					title : "修改操作提示",
					type : "error",
					text : "请检查密码是否符合标准！",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			if (password !==repassword ){
				swal({
					title : "修改操作提示",
					type : "error",
					text : "请检查两次密码输入是否一致！",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}

			$.ajax({
				url: "/forgetPassword",
				type: "POST", //提交方式
				data: $("#form-newPassword").serialize(),
				dataType: "json",
				success: (function (json) {
					if (json.state == 200) {
						swal({
							title: '重置密码成功',
							icon: 'success'
						}).then(function () {
							location.href = 'login'
						})
					} else {
						swal({
							title: '重置密码失败',
							icon: 'warning',
							text: json.message,
							button: {
								text: "确认",
								value: true,
							}
						}).then(function (isok) {
							if (isok) {
								return false;
							}
						})
					}
				})
			})
		})
	})





</script>


</html>
